(function () {
    "use strict";

    angular.module('core').factory('servicoAssincronoService', factory);
    factory.$inject = ['$http', '$q'];

    function factory($http, $q) {

        var _get = function (id) {
            var deferred = $q.defer();
            var args = { id: id };
            $http.post('/servicoassincrono/get', args)
                .success(function (data) { deferred.resolve(data); })
                .error(function (data, status, headers, config) { deferred.reject(data); });
            return deferred.promise;
        };
        var _getAll = function (args) {
            var deferred = $q.defer();
            $http.post('/servicoassincrono/getAll', args)
                .success(function (data) { deferred.resolve(data); })
                .error(function (data, status, headers, config) { deferred.reject(data); });
            return deferred.promise;
        };
        var _save = function (item) {
            var deferred = $q.defer();
            $http.post('/servicoassincrono/save', item)
                .success(function (data) { deferred.resolve(data); })
                .error(function (data, status, headers, config) { deferred.reject(data); });
            return deferred.promise;
        };

        var _getEvento = function (id) {
            var deferred = $q.defer();
            var args = { id: id };
            $http.post('/servicoassincrono/getEvento', args)
                .success(function (data) { deferred.resolve(data); })
                .error(function (data, status, headers, config) { deferred.reject(data); });
            return deferred.promise;
        };
        var _getAllEvento = function (args) {
            var deferred = $q.defer();
            $http.post('/servicoassincrono/getAllEvento', args)
                .success(function (data) { deferred.resolve(data); })
                .error(function (data, status, headers, config) { deferred.reject(data); });
            return deferred.promise;
        };
        var _saveEvento = function (item) {
            var deferred = $q.defer();
            $http.post('/servicoassincrono/saveEvento', item)
                .success(function (data) { deferred.resolve(data); })
                .error(function (data, status, headers, config) { deferred.reject(data); });
            return deferred.promise;
        };

        return {
            get: _get,
            getAll: _getAll,
            save: _save,
            getEvento: _getEvento,
            getAllEvento: _getAllEvento,
            saveEvento: _saveEvento
        };
    }

})();


